<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class news extends CI_Controller {

    function __construct() {
        parent::__construct();
        $this->load->model('m_news');
        $this->load->helper('date');
    }

    function index() {
        $data['list'] = $this->m_news->get_all_news()->result();
        $data['konten'] = 'v_news';
        $this->load->view('theme', $data);
    }

    function tambah_news() {
        $data['konten'] = 'v_news_tambah';
        $this->load->view('theme', $data);
    }

    function fungsi_tambah_news() {
        $data['judul'] = $this->input->post('judul');
        $data['news'] = $this->input->post('news');
        $data['date'] = $this->input->post('date');
        $res = $this->m_news->insert_news($data);
        if ($res) {
            header('location:' . base_url() . "news/" . $this->index());
        }
    }

    function edit_news() {
        $id = $this->uri->segment(3);
        $data['news'] = $this->m_news->get_by_id($id);
        $data['konten'] = 'v_news_edit';
        $this->load->view('theme', $data);
    }

    function update_news() {
        $data['judul'] = $_POST['judul'];
        $data['news'] = $_POST['news'];
        $data['date'] = $_POST['date'];
        $res = $this->m_news->update_news($data, $_POST['idnews']);
        if ($res) {
            header('location:' . base_url() . "news/" . $this->index());
        }
    }

    function hapus_news($idnews) {
        $res = $this->m_news->delete_news($idnews);
        if ($res) {
            header('location:' . base_url() . "news/" . $this->index());
        }
    }

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */